package com.jml.强软弱虚引用;


import java.util.HashMap;
import java.util.WeakHashMap;

/**
 * @author:jml
 * @date: 2019/5/8 16:01
 * @description：
 */
public class MyWeakHashMap {

    public static void main(String[] args) {
//        myHashMap();
        myWeakHashMap();
    }

    private static void myHashMap(){
        HashMap<Integer,String> map = new HashMap<>();
        Integer key = new Integer(1);
        String value = "HashMap";
        map.put(key,value);
        System.out.println(map);
        key=null;
        System.out.println(map);
        System.gc();
        System.out.println(map);
    }

    private static void myWeakHashMap(){
        WeakHashMap<Integer,String> map = new WeakHashMap<>();
        Integer key = new Integer(2);
        String value = "WeakHashMap";
        map.put(key,value);
        System.out.println(map);
        key=null;
        System.out.println(map);
        System.gc();
        System.out.println(map);
    }
}
